﻿//****************************************************************************
// Copyright (c) Microsoft Corporation. All rights reserved.
//****************************************************************************
using System;
using System.Configuration;
using System.Web.Configuration;
using System.Diagnostics.CodeAnalysis;

using Microsoft.FxCop.Sdk;

namespace Microsoft.FxCop.Rules.ASP.Security.Configuration
{
    public abstract class SystemWebConfigurationIntrospectionRule : WebConfigurationIntrospectionRule
    {
        protected SystemWebConfigurationIntrospectionRule(string name)
            : base(name)
        {
        }

        [SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", Justification = "If configuration is null, we need to let the exception bubble up which indicate an error in the engine.")]
        protected override ProblemCollection Check(System.Configuration.Configuration configuration)
        {
            SystemWebSectionGroup systemWeb;

            if ((systemWeb = configuration.SectionGroups.Get("system.web") as SystemWebSectionGroup) != null)
                return Check(systemWeb);

            return base.Problems;
        }

        protected abstract ProblemCollection Check(SystemWebSectionGroup webConfig);

    }
}
